package com.szsh.aiot.hsm.controller;

import com.google.gson.JsonObject;
import com.szsh.aiot.common.annotation.CustomPermission;
import com.szsh.aiot.common.annotation.Log;
import com.szsh.aiot.common.core.domain.AjaxResult;
import com.szsh.aiot.common.core.domain.RequestDto;
import com.szsh.aiot.common.enums.BusinessType;
import com.szsh.aiot.hsm.dto.enu.NumberEnum;
import com.szsh.aiot.hsm.service.TerminalService;
import com.szsh.aiot.hsm.utils.PermitValidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @Description:终端扫描
 * @Date 2023/10/30: 14:11
 * @Author: LOADING>>>>>
 */

@Controller
@RequestMapping("/terminal")
public class TerminalScanController {

    @Autowired
    private PermitValidUtil permitValidUtil;

    @Autowired
    private TerminalService terminalService;

    /**
     * 4.1 通过此接口可以对摄像头访问提醒方式增删改查操作;
     *
     * @param requestDto 请求参数
     * @return 处理结果
     */
    @RequestMapping(value = "/click/scanning")
    @Log(title = "摄像头提醒接口", businessType = BusinessType.OTHER)
    @CustomPermission(isValidateTyAccount = true)
    @ResponseBody
    public AjaxResult cameraAccessReminder(@RequestBody RequestDto requestDto) {
        String sequenceNo = requestDto.getSequenceNo();
        JsonObject requestParams = requestDto.getRequestJsonElement().getAsJsonObject();
        String operaType = permitValidUtil.getElementValue(requestParams, "operaType");
        String broadbandNO = permitValidUtil.getElementValue(requestParams, "broadbandNO");


        switch (operaType) {
            //由用户主动发起的设备扫描请求，开始扫描
            case NumberEnum.STR_1:
                String gatewayMac = permitValidUtil.getElementValue(requestParams, "gatewayMac");
                return terminalService.requireScan(gatewayMac,broadbandNO);

            //获取在线设备
            case NumberEnum.STR_2:
                return terminalService.queryOnlineDevice(broadbandNO);

            //网关弱密码查询
            case NumberEnum.STR_3:
                String scanID = permitValidUtil.getElementValue(requestParams, "scanID");
                gatewayMac = permitValidUtil.getElementValue(requestParams, "gatewayMac");
                return terminalService.checkGatewayPwdStrength(broadbandNO,gatewayMac,scanID);

            //获取用户漏洞信息
            case NumberEnum.STR_4:
                return terminalService.queryDeviceLeaks(broadbandNO);

            //查询网络防护开关
            case NumberEnum.STR_5:
                scanID = permitValidUtil.getElementValue(requestParams, "scanID");
                return terminalService.getNetSwitch(broadbandNO,scanID);


          /*  //判断用户是否安装安全插件
            case NumberEnum.STR_6:
                return terminalService.i(deviceIdList,broadbandNO);*/
            default:
                AjaxResult.badRequest("未知操作，请确认后重新操作");
                break;
        }
        return AjaxResult.badRequest("未知操作，请确认后重新操作");
    }

}
